package org.example.Thread02;

import java.util.concurrent.CopyOnWriteArrayList;

public class Dome_Thread08 {
    public static void main(String[] args) {
        //定义一个线程安全的集合类
        CopyOnWriteArrayList<Integer> copyOnWriteArrayList=new CopyOnWriteArrayList<>();
        //多个线程同时对这个集合进行读写操作
        for(int i=0;i<10;i++){
            int j=i+1;
            Thread t = new Thread(()->{
                copyOnWriteArrayList.add(j);
                System.out.println(copyOnWriteArrayList);
            });
            t.start();
        }
    }
}
